home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 4.1 KB | 182 lines | [TEXT/MPS ] |
- /*
- File: VirtualHFSFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __VIRTUALHFSFILE__
- #include "VirtualHFSFile.h"
- #endif
-
- /***********************************|****************************************/
-
- #pragma segment VirtualFile
-
- /***********************************|****************************************/
-
- extern ostream& DumpHex (ostream& s, const void *p, unsigned long size);
-
- /***********************************|****************************************/
-
- inline long min ( long a, long b )
- {
- return ( a < b) ? a : b;
- }
-
- /***********************************|****************************************/
-
- ostream& TVirtualHFSFile::operator >> ( ostream& s ) const
- {
- s << "TVirtualHFSFile @ " << ( void*) this << ", " << fSpec;
- return s << TAbstractFile::operator >> ( s );
- }
-
- /***********************************|****************************************/
-
- TVirtualHFSFile::TVirtualHFSFile(const FSSpec& location):
- TVirtualFile (),
- fSpec ( location ),
- fRefNum ( -1 )
- {
- Open ();
- }
-
- /***********************************|****************************************/
-
- TVirtualHFSFile::TVirtualHFSFile( short vRefNum, long dirID, const StringPtr name ):
- TVirtualFile (),
- fRefNum ( -1 )
- {
- fSpec.vRefNum = vRefNum;
- fSpec.parID = dirID;
- ::PLstrcpy ( fSpec.name, name );
- Open ();
- }
-
- /***********************************|****************************************/
-
- TVirtualHFSFile::~TVirtualHFSFile()
- {
- Close ();
- }
-
- /***********************************|****************************************/
-
- void TVirtualHFSFile::Open ()
- {
- if ( fRefNum == -1 )
- {
- ::FSpCreate(&fSpec, kDefaultCreator,kDefaultType, smRoman);
- ::FSpOpenDF(&fSpec, fsRdWrPerm, &fRefNum);
- SetPosition (fsFromStart, 0);
- }
- }
-
- /***********************************|****************************************/
-
- void TVirtualHFSFile::Close ()
- {
- if ( fRefNum != -1 )
- {
- ::FSClose(fRefNum);
- fRefNum = -1;
- }
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::DeleteFile()
- {
- return ::FSpDelete(&fSpec);
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::ReadData (void* buffer,long& count)
- {
- UpdateUsage();
-
- #if debug
- if (steveFlag.Flag(18)) {
- long pos; GetFPos(fRefNum, &pos);
- keith << "TVHFSFile::Read " << count << " bytes. pos=" << pos << endl;
- }
- #endif
-
- OSErr err = ::FSRead(fRefNum,&count,buffer);
-
- #if debug
- if (steveFlag.Flag(18)) {
- keith << "TVHFSFile::Read " << count << " bytes. err=" << err << endl;
- DumpHex(keith, buffer, min ( count, 48 ) );
- }
- #endif
-
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::WriteData (const void* buffer, long& count)
- {
- UpdateUsage();
-
- #if debug
- if (steveFlag.Flag(18)) {
- long pos; GetFPos ( fRefNum, &pos);
- keith << "TVHFSFile::WriteData(" << count << ") bytes position=" << pos << endl;
- DumpHex(keith, buffer, min ( count, 48 ) );
- }
- #endif
-
- OSErr err = ::FSWrite(fRefNum,&count,buffer);
-
- #if debug
- if (steveFlag.Flag(18)) {
- long pos; GetFPos ( fRefNum, &pos);
- keith << "TVHFSFile::WriteData(" << count << ") bytes. err=" << err << " newPos=" << pos << endl;
- }
- #endif
-
- return err;
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::SetEnd (long logEof)
- {
- UpdateUsage();
- return ::SetEOF (fRefNum, logEof);
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::GetEnd (long& logEof) const
- {
- return ::GetEOF (fRefNum, &logEof);
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::SetPosition (short posMode, long posOff)
- {
- UpdateUsage();
- return ::SetFPos (fRefNum,posMode,posOff);
- }
-
- /***********************************|****************************************/
-
- OSErr TVirtualHFSFile::GetPosition (long& filePos) const
- {
- return ::GetFPos (fRefNum, &filePos);
- }
-
- /***********************************|****************************************/
-